import Content from '@/sheep/layouts/content.vue';
import { request } from '@/sheep/request';
import { SELECT, CRUD } from '@/sheep/request/crud';
import { EXPORT } from '@/sheep/request/export';

const route = {
  path: 'commission',
  name: 'shop.admin.commission',
  component: Content,
  meta: {
    title: '分销',
  },
  children: [
    {
      path: 'agent',
      name: 'shop.admin.commission.agent',
      component: () => import('@/app/shop/admin/commission/agent/index.vue'),
      meta: {
        title: '分销商',
      },
    },
    {
      path: 'level',
      name: 'shop.admin.commission.level',
      component: () => import('@/app/shop/admin/commission/level/index.vue'),
      meta: {
        title: '分销商等级',
      },
    },
    {
      path: 'order',
      name: 'shop.admin.commission.order',
      component: () => import('@/app/shop/admin/commission/order/index.vue'),
      meta: {
        title: '分销订单',
      },
    },
    {
      path: 'log',
      name: 'shop.admin.commission.log',
      component: () => import('@/app/shop/admin/commission/log/index.vue'),
      meta: {
        title: '分销动态',
      },
    },
    {
      path: 'reward',
      name: 'shop.admin.commission.reward',
      component: () => import('@/app/shop/admin/commission/reward/index.vue'),
      meta: {
        title: '分销佣金',
      },
    },
    {
      path: 'goods',
      name: 'shop.admin.commission.goods',
      component: () => import('@/app/shop/admin/commission/goods/index.vue'),
      meta: {
        title: '分销商品',
      },
    },
  ],
};

const api = {
  agent: {
    ...CRUD('shop/admin/commission/agent', ['list', 'detail', 'edit', 'delete']),

    select: (params) => SELECT('shop/admin/commission/agent', params),

    changeParentUser: (id, data) =>
      request({
        url: `shop/admin/commission/agent/changeParentUser/${id}`,
        method: 'POST',
        data,
        options: {
          showSuccessMessage: true,
        },
      }),

    team: (id) =>
      request({
        url: `shop/admin/commission/agent/team/${id}`,
        method: 'GET',
      }),
  },
  level: {
    ...CRUD('shop/admin/commission/level'),
    select: (params) => SELECT('shop/admin/commission/level', params),
  },
  order: {
    ...CRUD('shop/admin/commission/order', ['list']),
    confirm: (params) =>
      request({
        url: `shop/admin/commission/order/confirm`,
        method: 'POST',
        params,
        options: {
          showSuccessMessage: true,
        },
      }),
    cancel: (params) =>
      request({
        url: `shop/admin/commission/order/cancel`,
        method: 'POST',
        params,
        options: {
          showSuccessMessage: true,
        },
      }),
    back: (params) =>
      request({
        url: `shop/admin/commission/order/back`,
        method: 'POST',
        params,
        options: {
          showSuccessMessage: true,
        },
      }),
    edit: (params) =>
      request({
        url: `shop/admin/commission/order/edit`,
        method: 'POST',
        params,
        options: {
          showSuccessMessage: true,
        },
      }),
    export: (params) => EXPORT(`shop/admin/commission/order/export`, params),
  },
  log: {
    ...CRUD('shop/admin/commission/log', ['list']),
  },
  reward: {
    ...CRUD('shop/admin/commission/reward', ['list']),
    export: (params) => EXPORT(`shop/admin/commission/reward/export`, params),
  },
  goods: {
    ...CRUD('shop/admin/commission/goods', ['list', 'detail', 'edit']),
  },
};

export { route, api };
